<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_cartoCSS_edit"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        .toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        #cartocssStr {
            height: 270px;
            width: 230px;
            display: block;
            background: #fff;
            border: none;
        }

    </style>
</head>
<body>
<div id="cartoContainer" class="toolbar panel panel-primary">
    <a href="#" style="position: absolute;right: 15px;top: 15px;z-index: 100" onclick="toggle(event)" data-i18n="resources.text_hide"></a>
    <div id="text" class='panel-heading'><h5 class='panel-title text-center' data-i18n="resources.text_cartoCSSStyleChart"></h5></div>
    <div class='panel'>
        <div class='input-group'>
            <textarea id="cartocssStr"></textarea>
        </div>
    </div>
   <!-- <input type="button" class="btn btn-default" value="refresh" onclick="refresh()"
           style="margin-bottom: 10px"/>-->
</div>
<div id="map"></div>
    <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
    <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, layer, editor, cartoCssStr, cartoContainer,
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-china400/rest/maps/China";
    init();

    function init() {
        if (!document.createElement('canvas').getContext) {
            widgets.alert.showAlert(resources.msg_supportCanvas,false);
            return;
        }
        //语言默认为跟当前浏览器的语言一样,当要切换至英文时,要先引入英文的语言包，然后用以下语言切换
        //SuperMap.Lang.setCode("en");

        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        cartoCssStr = document.getElementById("cartocssStr");
        cartoCssStr.setAttribute("disabled", true);
        var cartoCss = cartoCssStr.value;
        layer = new SuperMap.Layer.TiledVectorLayer("China", url, {
            cacheEnabled: true,
            returnAttributes: true
        }, {useLocalStorage: true, cartoCss: cartoCss});
        editor = new SuperMap.Control.TiledVectorLayerEditor({"layer": layer, "position": {"x": 0, "y": 0}});
        editor.events.on({
            "cartocsschange": function (event) {
                cartoCssStr.value = event.cartoCss;
            }
        });
        editor.activate();
        layer.events.on({"layerInitialized": addLayer});

        cartoContainer = document.getElementById("cartoContainer");
    }

    function addLayer() {
        map.addLayers([layer]);
        map.addControls([editor]);
        var center = new SuperMap.LonLat(11793760, 4407704);
        map.setCenter(center, 6);
    }

 /*   function refresh() {
        editor.position = {"x": 150, "y": 536};
        editor.autoHide = true;
        editor.editorName = "我的矢量地图编辑器";
        editor.refresh();
    }*/

    function toggle(event) {
        event = event || window.event;
        var element = SuperMap.Event.element(event);
        SuperMap.Element.toggleClass(cartoContainer, "hide");
        if (SuperMap.Element.hasClass(cartoContainer, "hide")) {
            element.innerHTML = resources.btn_open;
        } else {
            element.innerHTML = resources.text_hide;
        }
    }
</script>

</body>
</html>